<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function handleDate(arr,bol){
      console.log(arr.length)
      let sum = 0
      let average=0
        for(let i=0;i<arr.length;i++){
          sum=sum+arr[i]
        }
         average = sum / arr.length
        if (bol === 'true') {
          document.write(sum)
       }
      else if(bol === 'false'){
       document.write(average)
      }else{
         document.write(sum)
      }
    }
    let arr1=[1,4,5,3,7]
    let bolean=prompt(`输入true和其他求和输入false求平均值`)
    let re=handleDate(arr1, bolean)
  </script>
</body>
</html>